<?php
	if(!empty($_GET['nama'])){
		$param_nama=$_GET['nama'];
	}else{
		$param_nama=$_POST['nama'];
	}
?>
<div class="judul_content">Data Produk</div>

<form method="post" action="utama.php?module=mod_produk">
	<table class="tbl_cari">
		<tr>
			<td width="65">Pencarian  : </td>
			<td width="200"><input type="text" name="nama" value="<?php echo $param_nama; ?>" class="frm_cari" /></td>
			<td><input name="submit" type="submit" class="submit" value="Cari" /></td>
			<td></td>
			<td align="right"><a href="utama.php?module=mod_produk&view=form_tambah"> <input type="button" value="Tambah Data" class="tambah"></a></td>
		</tr>
	</table>
</form>

<table class="table" border="1">
    <tr>
        <th width="20" rowspan="2">No</th>
		<th rowspan="2">Gambar</th>
		<th rowspan="2">Kode</th>
        <th rowspan="2">Nama Produk</th>
		<th rowspan="2">Kategori</th>
		<th colspan="2">Diskon</th>
		<th rowspan="2">Harga</th>
        <th width="60" rowspan="2">Aksi</th>
    </tr>
	<tr>
		<th>Member</th>
		<th>Umum</th>
	</tr>
    <?php
    	$p= new paging ;
		$batas= 5;

		//cek halaman dan posisi halaman
		$posisi = $p ->cariposisi($batas) ;

    	$sttmt = $koneksi->query("select * from produk p inner join kategori k on p.id_kategori = k.id_kategori where p.nama_produk like '%$param_nama%' order by p.id_produk desc limit $posisi,$batas");
    	$no = $posisi + 1;

		while($hasil = $sttmt->fetch(PDO::FETCH_ASSOC)){
    		?>
		    <tr>
		        <td><?php echo $no; ?></td>
				<td> <img src="../produk/<?php echo $hasil[gambar]; ?>" height="50"> </td>
				<td><?php echo $hasil[kode]; ?></td>
		        <td><?php echo $hasil[nama_produk]; ?></td>
				<td><?php echo $hasil[kategori]; ?></td>
				<td><?php echo $hasil[diskon_member]; ?></td>
				<td><?php echo $hasil[diskon_umum]; ?></td>
				<td><?php echo $hasil[harga]; ?></td>
		        <td>
					<a href="utama.php?module=mod_stok&id=<?php echo $hasil[id_produk]; ?>">
						<img src="asset/images/detail.png" title="Edit">
					</a>
					<!--<a href="utama.php?module=mod_gambar&id=<?php echo $hasil[id_produk]; ?>">
						<img src="asset/images/detail.png" title="Edit">
					</a>-->
		        	<a href="utama.php?module=mod_produk&view=form_edit&id=<?php echo $hasil[id_produk]; ?>">
						<img src="asset/images/edit.png" title="Edit">
					</a>
		        	<a href="utama.php?module=mod_produk&act=hapus&id=<?php echo $hasil[id_produk]; ?>" onclick="return confirm('Anda yakin ingin Menghapus Data ?')">
		        		<img src="asset/images/delete.png" title="Hapus">
		        	</a>
		        </td>
		    </tr>
    		<?php
    		$no++;
		}
	?>
</table>
<br>
<?php
	$sttmt = $koneksi->query("select * from produk where nama_produk like '%$param_nama%' order by id_produk desc");
	$jumlah_data = $sttmt->rowCount();
	//dapatkan jumlah halaman
	$jumlah_halaman= $p->jumlahhalaman($jumlah_data,$batas);
	//cetak link
	$linkhalaman=$p->navhalaman($_GET['halaman'],$jumlah_halaman,$_SERVER['PHP_SELF']."?module=mod_produk","nama=$param_nama");
	print($linkhalaman);
?>
        